package com.wish.g04.financial.controller;

import com.wish.g04.base.dto.JrProductDTO;
import com.wish.g04.base.entity.JrProduct;
import com.wish.g04.base.service.IJrProductService;
import com.wish.g04.common.core.web.controller.BaseController;
import com.wish.g04.common.core.web.domain.AjaxResult;
import com.wish.g04.common.core.web.page.TableDataInfo;
import com.wish.g04.common.log.annotation.Log;
import com.wish.g04.common.log.enums.BusinessType;
import com.wish.g04.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 金融产品审核Controller
 * 
 * @author Z-7
 * @date 2022-05-27
 */
@RestController
@RequestMapping("/auditor")
public class JrProductAuditorController extends BaseController
{
    @Autowired
    private IJrProductService jrProductService;

    /**
     * 查询金融产品待审核列表
     */
    @GetMapping("/list")
    public TableDataInfo list(JrProductDTO jrProductDTO)
    {
        startPage();
        List<JrProduct> list = jrProductService.getAuditorList(jrProductDTO.getJrProductType());
        return getDataTable(list);
    }

    /**
     * 通过审核
     */
    @PreAuthorize(hasPermi = "financial:auditor:auditor")
    @Log(title = "金融产品管理-通过", businessType = BusinessType.INSERT)
    @PostMapping("/adopt/{id}")
    public AjaxResult adopt(@PathVariable Integer id)
    {
        boolean flag = jrProductService.adopt(id);
        if (flag) {
            return AjaxResult.success();
        }
        return AjaxResult.error("操作失败");
    }

    /**
     * 通过审核
     */
    @PreAuthorize(hasPermi = "financial:auditor:auditor")
    @Log(title = "金融产品管理-驳回", businessType = BusinessType.INSERT)
    @PostMapping("/reject/{id}")
    public AjaxResult reject(@PathVariable Integer id)
    {
        boolean flag = jrProductService.reject(id);
        if (flag) {
            return AjaxResult.success();
        }
        return AjaxResult.error("操作失败");
    }
}
